#!/usr/bin/perl
#
# Copyright (c) 2012 Xumerle Luciano. All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#

# FIELDS IN VCF
# CHROM    POS     ID      REF     ALT     QUAL    FILTER  INFO
# OUTPUT FIELDS (NO HEADER)
# CHROM    POS     ID      REF     ALT     QUAL    FILTER  TYPE   DBSNPBUILDID

use strict;
use warnings;

open( FILE, $ARGV[0] ) || die "NO file.vcf in input";
while (<FILE>)
{
    chomp;
    next if (m/^#/);
    my @a = split "\t";
    my @b = split ';', $a[$#a];
    pop @a;
    my $type         = '';
    my $dbSNPBuildID = '';
    foreach my $ft (@b)
    {
        $type         = $1 if ( $ft =~ m/^VC=(.+)$/i );
        $dbSNPBuildID = $1 if ( $ft =~ m/^dbSNPBuildID=(.+)$/i );
    }
    print join( "\t", @a, $type, $dbSNPBuildID ), "\n";
}
close FILE;

